<template>
  <div style="position: relative; padding: 0; margin: 0">
    <Previewer ref="viewer" style="padding: 0; margin: 0" />
  </div>
</template>
<script lang="ts" setup>
// import type { ComponentDataType } from "@/RtDataView/RonTonDataView";
import {
  Previewer,
  //useSnapshotState,
  useUserStoreWithOut
} from "@/RtDataView/RonTonDataView";
import { ref, onMounted } from "vue";
import { getDataViewByID } from "@/api/application";
import router from "@/router";
import getURL from "@/utils/http/address";
import { getToken } from "@/utils/auth";
import { ElMessage } from "element-plus";

const viewer = ref();

const userData = useUserStoreWithOut();
//const snapShotState = useSnapshotState(); //获取预览数据

onMounted(async () => {
  userData.setToken("Bearer " + getToken().accessToken);
  userData.setServerURL(getURL + "/api/DataView/");
  const form = { appId: Number(router.currentRoute.value.name) };
  console.log(form);
  const Rs = await getDataViewByID(form);
  if (Rs.isSuccess) {
    console.log(Rs);
    viewer.value!.setLayoutData(JSON.parse(Rs.result.dataView));
  } else {
    ElMessage({ message: Rs.msg, type: "error" });
  }
});
</script>
